﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_SaveDailywordAnswer')
BEGIN
    PRINT 'Dropping Procedure proc_cm_SaveDailywordAnswer'
    DROP  Procedure  proc_cm_SaveDailywordAnswer
END
GO

PRINT 'Creating Procedure proc_cm_SaveDailywordAnswer'
GO

CREATE PROCEDURE [dbo].[proc_cm_SaveDailywordAnswer]
	@pDailywordAnswerId uniqueidentifier
	, @pDailywordQuestionId uniqueidentifier
	, @pDailywordStatusId uniqueidentifier
	, @pAnswerTxt nvarchar(100)
	, @pCorrectInd bit
AS
BEGIN
	SET NOCOUNT ON

	UPDATE 
		[dbo].[tbl_dailyword_answer]
	SET 
		[dailyword_question_id] = @pDailywordQuestionId
		,[dailyword_status_id] = @pDailywordStatusId
		,[answer_txt] = @pAnswerTxt
		,[correct_ind] = @pCorrectInd
		,[updated_dttm] = GETDATE()
	WHERE
		[dailyword_answer_id] = @pDailywordAnswerId

	IF @@ROWCOUNT = 0
	BEGIN
		INSERT INTO [dbo].[tbl_dailyword_answer]
		(
			[dailyword_answer_id]
			,[dailyword_question_id]
			,[dailyword_status_id]
			,[answer_txt]
			,[correct_ind]
			,[created_dttm]
			,[updated_dttm]
		)
		VALUES
		(
			@pDailywordAnswerId
			,@pDailywordQuestionId
			,@pDailywordStatusId
			,@pAnswerTxt
			,@pCorrectInd
			,GETDATE()
			,GETDATE()
		)
	END
END
GO

GRANT EXEC ON dbo.proc_cm_SaveDailywordAnswer TO PUBLIC
GO

